<template>
  <div class="boxok">
    <!-- 头部 -->
    <div class="htear">
      <div class="left">
        <div
          @click="$router.go(-1)"
          class="return iconfont icon-arrowRight-copy-copy"
        ></div>
        <div class="name">大神</div>
      </div>
      <div class="age">
        <router-link tag="div" to="/schoolboy" class="com">男生</router-link>
        <router-link tag="div" to="/girlstudent">女生</router-link>
      </div>
      <div class="right">
        <router-link tag="div" to="/search" class="searchcon iconfont icon-31sousuo"></router-link>
        <div
          is-link
          @click="showPopup"
          class="classification iconfont icon-a-gengduofenlei"
        ></div>
      </div>
    </div>
    <!-- 弹出内容 -->
    <van-popup
      closeable
      v-model="show"
      position="top"
      :style="{ height: '45%' }"
    >
      <div class="boxpopup">
        <!-- 头部 -->
        <div class="htears">
          <div class="left">
            <div
              @click="$router.go(-1)"
              class="return iconfont icon-arrowRight-copy-copy"
            ></div>
            <div class="name">大神</div>
          </div>
        </div>
        <!-- 分类 -->
        <div class="guide-nav">
          <router-link tag="div" to="/schoolboy" class="box">
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-home-copy"></use>
            </svg>
            <div class="boxtext">首页</div>
          </router-link>
          <router-link tag="div" to="/classification" class="box">
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-fenlei"></use>
            </svg>
            <div>分类</div>
          </router-link>
          <router-link tag="div" to="/rankinglist" class="box">
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-daochu1024-02"></use>
            </svg>
            <div>排行榜</div>
          </router-link>
          <router-link tag="div" to="/cover" class="box">
            <svg class="icon" aria-hidden="true">
              <use
                xlink:href="#icon-a-travelhotelholidayvacationcdlistingboo"
              ></use>
            </svg>
            <div>免费</div>
          </router-link>
          <router-link tag="div" to="/end" class="box">
            <svg class="icon sw" aria-hidden="true">
              <use xlink:href="#icon-wanjietuijian"></use>
            </svg>
            <div>完本</div>
          </router-link>
          <router-link tag="div" to="/okami" class="box">
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-huangguan"></use>
            </svg>
            <div>大神</div>
          </router-link>
        </div>
        <!-- 我的书架 -->
        <router-link tag="div" to="/bookshelf" class="mybookshelf">我的书架</router-link>
      </div>
    </van-popup>
    <!-- 大神新书 -->
    <div class="hot">
      <div class="hotnav">
        <div class="div">大神新书</div>
      </div>
      <!-- 书籍 -->
      <div class="content">
        <!-- 轮播图 -->
        <div class="swiper-container-02">
          <div class="swiper-wrapper">
            <div
              @click="bookdeta(item.id)"
              class="swiper-slide item"
              v-for="(item, index) in imalists"
              :key="index"
            >
              <div class="img">
                <img :src="item.image" alt="" />
              </div>
              <p class="text">{{ item.title }}</p>
              <p class="name">{{ item.name }}</p>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 白金列表 -->
    <div style="margin-bottom: 0px" class="hot">
      <div class="hotnav">
        <div class="div">白金列表</div>
      </div>
      <!-- 推荐作者 -->
      <router-link
        tag="div"
        :to="'/author?id=' + item.id"
        v-for="(item, index) in platinumlists.slice(0, planums)"
        :key="index"
        class="author"
      >
        <div class="topimg">
          <img :src="item.images" alt="" />
          <span>白金</span>
        </div>
        <div class="authorname">
          <div class="name">{{ item.name }}</div>
          <div class="introduce">{{ item.text }}</div>
        </div>
        <div class="more iconfont icon-arrowRight-copy-copy-copy"></div>
      </router-link>
    </div>
    <!-- 加载更多 -->
    <div v-show="planums != platinumlists.length" @click="platinum" class="load">
      加载跟多<span class="iconfont"></span>
    </div>
    <!-- 间隙 -->
    <div class="br"></div>
    <!-- 大神列表 -->
    <div style="margin-bottom: 0px" class="hot">
      <div class="hotnav">
        <div class="div">大神列表</div>
      </div>
      <!-- 推荐作者 -->
      <router-link
        tag="div"
        :to="'/author?id=' + parseInt(item.id + 100)"
        v-for="(item, index) in okamilists.slice(0, okanums)"
        :key="index"
        class="author"
      >
        <div class="topimg">
          <img :src="item.images" alt="" />
          <span style="background-color: #f1686f">大神</span>
        </div>
        <div class="authorname">
          <div class="name">{{ item.name }}</div>
          <div class="introduce">{{ item.text }}</div>
        </div>
        <div class="more iconfont icon-arrowRight-copy-copy-copy"></div>
      </router-link>
    </div>
    <!-- 间隙 -->
    <div class="br"></div>
    <footers></footers>
  </div>
</template>

<script>
import Swiper from "swiper";
import footers from '../components/base/footers.vue';
export default {
  components: { footers },
  data() {
    return {
      //弹出判断
      show: false,
      // 主编推荐列表数据
      imalists: [
        {
          id: 0,
          image: "https://bookcover.yuewen.com/qdbimg/349573/1030879001/150",
          title: "被揍就能变强",
          name: "新丰",
        },
        {
          id: 1,
          image: "https://bookcover.yuewen.com/qdbimg/349573/1030925549/150",
          title: "星界使徒",
          name: "齐佩甲",
        },
        {
          id: 2,
          image: "https://bookcover.yuewen.com/qdbimg/349573/1031830919/150",
          title: "联盟从4396开始",
          name: "超气人作者",
        },
        {
          id: 3,
          image: "https://bookcover.yuewen.com/qdbimg/349573/1031299884/150",
          title: "看个直播，我竟被当成了仙师？",
          name: "我真不想出名",
        },
        {
          id: 4,
          image: "https://bookcover.yuewen.com/qdbimg/349573/1027549281/150",
          title: "西游，我体内有九只金乌",
          name: "可怜的懒虫",
        },
        {
          id: 5,
          image: "https://bookcover.yuewen.com/qdbimg/349573/1029100123/150",
          title: "小兵活下去",
          name: "蓝色星轮",
        },
        {
          id: 6,
          image: "https://bookcover.yuewen.com/qdbimg/349573/1027551057/150",
          title: "重生之似水流年",
          name: "苍山月",
        },
      ],
      // 白金列表
      platinumlists:[],
      // 白金列表数量
      planums: 5,
      // 大神列表
      okamilists:[],
      // 大神列表数量
      okanums: 5,
    };
  },
  methods: {
    //头部弹出
    showPopup() {
      this.show = true;
    },
    //加载更多
    platinum() {
      this.planums += 5;
    },
    // 路由跳转传参
    bookdeta(id) {
      this.$router.push({
        path: "/bookdetails",
        query: {
          id: id
        },
      });
    },
    getScroll() {
      // console.log("滚动高度", window.pageYOffset);
      //   console.log(
      //     "距离顶部高度",
      //     this.$refs.obtain.getBoundingClientRect().top
      //   );

      // 获取页面高度
      // console.log(document.documentElement.clientHeight);
      let ffoheight = document.documentElement.clientHeight;
      // 获取滚动条上距离顶部高度
    //   let scrollheight = window.pageYOffset;
    //   console.log(scrollheight)
      // 获取页面总长度
      let scrollHeight = document.body.scrollHeight;
      // 获取滚动条上距离顶部高度(兼容)
      let scrollTop =document.documentElement.scrollTop || document.body.scrollTop;

    //   console.log(document.body.scrollHeight);

      //   console.log(scrollheight);

      //通过页面高度来决定加载的多少
      if (ffoheight + scrollTop >= scrollHeight) {
         setTimeout(() => {
          this.okanums+=5
        }, 300);
      }
    },
  },
  mounted() {
    new Swiper(".swiper-container-02", {
      pagination: ".swiper-pagination-02",
      slidesPerView: 4.5,
      paginationClickable: true,
      observer: true,
      observeParents: true,
      spaceBetween: 30,
    });
    window.addEventListener("scroll", this.getScroll);
  },
  created(){
    this.$axios.get("/static.json").then((res) => {
      let data = res.data;
      this.platinumlists = data.platinumlists;//白金数据列表
      this.okamilists = data.okamilists;//大神数据列表
    })
  }
};
</script>

<style lang="less">
.boxok {
  // 关闭按钮
  .van-popup__close-icon--top-right {
    top: 13px;
  }
  .boxpopup {
    .htears {
      width: 100%;
      display: flex;
      height: 22px;
      padding: 11px 0px 10px 0px;
      justify-content: space-between;
      align-items: center;
      .age {
        display: flex;
        height: 24px;
        border: 1px solid #ed424b;
        border-radius: 3px;
        div {
          font-size: 15px;
          line-height: 24px;
          color: #ed424b;
          padding: 0px 10px;
        }
        .com {
          background: #ed424b;
          color: white;
        }
      }
      .left,
      .right {
        display: flex;
        div {
          padding: 0px 10px;
          text-align: center;
          font-size: 18px;
          color: #3c3b3b;
        }
        .name {
          font-size: 14px;
          color: #424141;
        }
        .return {
          color: black;
        }
      }
    }
    .guide-nav {
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      padding: 0px 16px;
      .box {
        width: 58px;
        height: 58px;
        line-height: 58px;
        text-align: center;
        margin: 12px 24px;
        div {
          position: relative;
          top: -33px;
          font-size: 14px;
        }
      }
    }
    .mybookshelf {
      margin: 20px 50px;
      text-align: center;
      padding: 8px 0px;
      font-size: 14px;
      color: white;
      font-weight: 500;
      background-color: #ed424b;
      border-radius: 20px;
    }
    .sw {
      font-size: 40px;
    }
  }
  .htear {
    width: 100%;
    display: flex;
    height: 22px;
    padding: 11px 0px 10px 0px;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #e8e7e7;
    background-color: white;
    .left,
    .right {
      display: flex;
      div {
        padding: 0px 10px;
        text-align: center;
        font-size: 18px;
        color: #3c3b3b;
      }
      .name {
        font-size: 14px;
        color: #424141;
      }
      .return {
        color: black;
      }
    }
    .age {
      display: flex;
      height: 24px;
      border: 1px solid #ed424b;
      border-radius: 3px;
      div {
        font-size: 15px;
        line-height: 24px;
        color: #ed424b;
        padding: 0px 10px;
      }
      .com {
        background: #ed424b;
        color: white;
      }
    }
  }
  .hot {
    width: calc(100% - 30px);
    padding: 0px 15px;
    background: white;
    margin-bottom: 12px;
    .hotnav {
      padding: 15px 0px;
      display: flex;
      align-items: center;
      padding-bottom: 20px;
      position: relative;
      .div {
        font-size: 16px;
        font-weight: 600;
        padding: 0px 9px;
        border-left: 2px solid red;
        color: #33373d;
      }
      span {
        color: #969ba3;
        font-size: 13px;
        margin-left: 8px;
      }
      .more {
        font-size: 14px;
        color: #a4a8c3;
        border: 0px;
        position: absolute;
        top: 15px;
        right: 0px;
      }
    }

    .swiper-container-02 {
      max-width: 345px;
      overflow: hidden;
      .swiper-wrapper {
        display: flex;
      }
    }
    .content {
      width: 100%;
      padding-bottom: 15px;
      .item {
        width: 66px;
        .img {
          width: 66px;
          height: 88px;

          img {
            width: 100%;
            height: 100%;
          }
        }
        .text {
          width: 66px;
          overflow: hidden;
          font-size: 13px;
          max-height: 36px;
          color: #3a3939;
          margin: 5px 0px;
        }
        .name {
          font-size: 12px;
          color: #969ba3;
          height: 12px;
          width: 66px;
          line-height: 12px;
          overflow: hidden;
        }
      }
    }
    .author {
      width: 100%;
      height: 85px;
      display: flex;
      position: relative;
      background-color: white;
      .topimg {
        width: 48px;
        height: 48px;
        position: relative;
        margin-right: 12px;
        padding: 16px 0px;
        img {
          width: 100%;
          border-radius: 50%;
        }
        span {
          position: absolute;
          bottom: 16px;
          left: 5px;
          font-size: 12px;
          color: white;
          background-color: #b3a7ff;
          padding: 0px 7px 0px 7px;
          border-radius: 8px;
          border-top: 1px solid white;
          border-left: 1px solid white;
          border-right: 1px solid white;
        }
      }
      .authorname {
        padding: 16px 0px;
        flex: 1;
        border-top: 1px solid whitesmoke;
        .name {
          color: #33373d;
          font-size: 16px;
          overflow: hidden;
          font-weight: 600;
          white-space: nowrap;
          margin-bottom: 5px;
        }
        .introduce {
          margin-top: 10px;
          font-size: 14px;
          width: 259px;
          color: #a8a7a9;
          height: 16px;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }
      }
      .more {
        position: absolute;
        right: 16px;
        top: calc(85px / 2 - 16px / 2);
        margin: auto;
      }
    }
  }
  .load {
    width: 100%;
    background-color: white;
    border-top: 1px solid #f0f1f2;
    text-align: center;
    height: 45px;
    line-height: 45px;
    color: #bbb;
    font-size: 14px;
  }
  .br {
    height: 12px;
  }
}
</style>